package DoThiThuyDiem_10130115_BTLCMCB;


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy {
	public static void fileCopy(String sFile, String destFile, boolean move)
			throws IOException {
		FileInputStream fis = new FileInputStream(sFile);
		BufferedInputStream bif = new BufferedInputStream(fis);
		FileOutputStream fos = new FileOutputStream(destFile);
		BufferedOutputStream bof = new BufferedOutputStream(fos);

		int byteToRead = 1024;
		int d = 0;
		while (true) {
			byte[] array = new byte[byteToRead];
			int n = fis.read(array);
			if (n==-1) {
				break;
			}
			fos.write(array, 0, n);
		}
		fis.close();
		fos.close();
		File f = new File(sFile);
		if (move) {
			f.delete();
		}
	}
	public static void coppyFile(String s, String d) throws Exception{
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(s));
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(d),1000);
		int b = bis.read();
		while (b != 1) {
			bos.write(b);
			b=bis.read();
		}
		bis.close();
		bos.close();
	}
	public static void main(String[] args) throws Exception {
//		fileCopy("D:\\test\\aa.txt", "D:\\test\\aa1.txt", true);
		coppyFile("D:\\test\\ads.txt", "D:\\GiaoDien\\ads1.doc");
	}

}
